#ifndef _PIXELBUFFER_H
#define _PIXELBUFFER_H

#include "Arduino.h"
#include "settings.h"
#include "byteblock.h"


struct Letter {
  char letter;
  uint8_t length;
  byte pixel_arr[3];
};


class PixelBuffer {
  private:
    Letter *letter_ptr_array[maxLetters] = {nullptr};  // Array of pointers for the struct Letter (I hope)
    uint8_t num_letters;

    uint8_t get_next_letter_position(void);
    uint8_t get_last_letter_position(void);
  
  public:
    byte pixel_arr[pixelBufferLength] = {0};
    
    uint8_t push_letter(const Letter *letter);
    uint8_t push_letter(const char);
    void clear_letters(void);
    void set_text(const char *text_ptr, const bool append=false);  // sets new text, returns end_position in Letter array
    void set_int(int num, const bool append=false);
    void set_float(double num, const bool append=false);
    
    void set_pixelbuffer(const byte *src_arr, uint8_t len);  // copies array to pixelbuffer
    byte* get_buffer_array(void);
    void draw_pixelbuffer(const bool insert_blank=true);  // redraws buffer
    void invert_pixelbuffer(void); //inverts pixelbuffer
    void center_pixelbuffer(void);
    void clear_pixelbuffer(void);  // clears pixel buffer
    uint8_t move_pixelbuffer_left(const byte insert);
    uint8_t move_pixelbuffer_right(const byte insert);
    void move_pixelbuffer_up(void);
    void move_pixelbuffer_down(void);
    
    #ifdef DEBUG
      void print_pixelbuffer(void);
    #endif  //DEBUG

    void insert_stat_column(float min, float max, float step);

    ByteBlock get_byteblock_as_rows(const uint8_t start_column);
    ByteBlock get_byteblock_as_columns(const uint8_t start_column);

    PixelBuffer(void) : num_letters(0) {};
    PixelBuffer(const PixelBuffer &pixbuf);
};

#ifdef DEBUG
void test_pixelbuffer(void);
#endif // DEBUG

#endif //_PIXELBUFFER_H